package com.boer;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.EasyExcel;

import java.util.List;

public class UpdateDeviceRegister {
    public static void main(String[] args) {

        String filePath = "C:\\Users\\hcf\\Desktop\\主机-知轮-需推大车-11-28.xlsx";  // 替换为实际文件路径

        // 读取 Excel 文件
        List<DeviceRegisterRequest> dataList = EasyExcel.read(filePath)
                .head(DeviceRegisterRequest.class)
                .sheet().headRowNumber(1)
                .doReadSync();
        // 创建请求对象

        int count =0;
        for (DeviceRegisterRequest deviceRegisterRequest : dataList) {
            postHttp(deviceRegisterRequest,deviceRegisterRequest.getLicensePlate());
            count ++;
//            if (count ==2) {
//                return;
//            }
        }
    }

    private static void postHttp(DeviceRegisterRequest requestObj, String licensePlate) {
        // 将对象转换为 JSON 字符串
        String requestBody = JSONUtil.toJsonStr(requestObj);

        // 构建请求
        HttpResponse response = HttpRequest.post("https://www.56dache.com/dache-wmms-admin/handler/deviceRegister/updateDeviceRegister.update")
            .header("accept", "application/json, text/plain, */*")
            .header("accept-language", "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7")
            .header("cache-control", "no-cache")
            .header("content-type", "application/json;charset=UTF-8")
            .header("cookie", "JSESSIONID=54c3c82a-b44c-4c7f-a481-c085be65d313; SERVERID=17db52a41f1405e932d014be0c02fb21|1732792861|1732702746")
            .header("origin", "https://sh.sy.tehst.56luntai.com:18886")
            .header("pragma", "no-cache")
            .header("priority", "u=1, i")
            .header("referer", "https://www.56dache.com/dache-wmms-admin/")
            .header("sec-ch-ua", "\"Chromium\";v=\"128\", \"Not;A=Brand\";v=\"24\", \"Google Chrome\";v=\"128\"")
            .header("sec-ch-ua-mobile", "?0")
            .header("sec-ch-ua-platform", "\"Windows\"")
            .header("sec-fetch-dest", "empty")
            .header("sec-fetch-mode", "cors")
            .header("sec-fetch-site", "same-origin")
            .header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36")
            .body(requestBody)
            .execute();

        // 打印响应
       // System.out.println(response);
        System.out.println(licensePlate);
        System.out.println(response.body());
    }
}
